package ru.spbu.math.android.cbrf.application;

import ru.spbu.math.android.cbrf.model.RateType;
import ru.spbu.math.android.cbrf.application.EditRateTypeListAdapter;
import ru.spbu.math.android.cbrf.dataprovider.ProviderManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.util.Log;

public class EditOnRateTypeClickListener implements OnMultiChoiceClickListener {

	private static final String TAG = "Application.EditOnRateTypeClick";
	
	private EditRateTypeListAdapter rateListAdapter;
	private Context context;
	
	public EditOnRateTypeClickListener(EditRateTypeListAdapter rateListAdapter, Context context){
		super();
		this.rateListAdapter = rateListAdapter;
		this.context = context;
	}

	@Override
	public void onClick(DialogInterface dialog, int which, boolean isChecked) {
		RateType rateType = (RateType) rateListAdapter.getItem(which);
		String idRateType = ProviderManager.getInstance(context).getExternalIdByRateType(rateType);
		if(isChecked){
			Log.d(TAG, "Select rateType : " + rateType.getName());
			AppConfigure.saveIdRateType(context, idRateType);
			AppConfigure.saveIsChecked(context, idRateType, isChecked, which);
		} else{
			Log.d(TAG, "Delete rateType : " + rateType.getName());
			AppConfigure.deleteIdRateType(context, idRateType);
			AppConfigure.saveIsChecked(context, idRateType, isChecked, which);
		}
		
	}
	

}

	
